package com.concurrency.example.singleton;

public class SingletonExample4 {
    private SingletonExample4() {

    }

    public static SingletonExample4 getInstance() {
        return SingletonEnum.INSTANCE.singleton;
    }

    private enum SingletonEnum {
        INSTANCE;

        private SingletonExample4 singleton;

        //JVM保证只执行一次
        SingletonEnum() {
            singleton = new SingletonExample4();
        }
    }

    public static void main(String[] args) {
        System.out.println(getInstance().hashCode());
        System.out.println(getInstance().hashCode());
    }
}
